#!/bin/bash
# FurryOS Log Compressor - Keeps only essential info, removes noise

compress_log() {
    logfile="$1"
    output="${logfile%.log}.compressed.log"

    # Filter out repetitive/verbose lines, keep only important ones
    grep -v "Unrecognised xattr prefix" "$logfile" | \
    grep -v "^[[:space:]]*$" | \
    grep -E "(^\[|^Starting|^Building|^Copying|^SUCCESS|^ERROR|^WARNING|^Injecting|ISO:|completed)" > "$output"

    original_size=$(du -h "$logfile" | cut -f1)
    compressed_size=$(du -h "$output" | cut -f1)

    echo "✅ Log compressed!"
    echo "Original:    $original_size"
    echo "Compressed:  $compressed_size"
    echo "Output:      $output"
    echo ""
}

# Find and compress all build logs
for log in build-*.log; do
    if [ -f "$log" ]; then
        compress_log "$log"
    fi
done
